package io.renren.modules.app.controller;

import io.renren.common.exception.RRException;
import io.renren.common.utils.AbstractController;
import io.renren.common.utils.DateUtils;
import io.renren.modules.app.request.JhdzQueryRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import io.renren.modules.app.request.BdcJfQueryRequest;
import io.renren.modules.app.service.H5payService;
import io.renren.common.utils.R;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Map;


/**
 * 不动产支付系统接口
 *
 * @author Shark
 * @email shark@126.com
 * @date 2019-08-16 10:49:56
 */
@Slf4j
@Api(tags = "不动产支付系统接口")
@RestController
@RequestMapping("/api/h5pay")
public class H5payController extends AbstractController {
    @Autowired
    private H5payService h5payService;

    /**
     * 1.1银行缴费查询接口
     */
    @PostMapping("bdcJfQuery")
    @ApiOperation("1.1银行缴费查询接口")
    @ResponseBody
    public R bdcJfQuery(@Valid @RequestBody BdcJfQueryRequest request) {

        try {
            Map map = h5payService.bdcJfQuery(request);
            return R.ok().put("data", map);
        } catch (RRException e) {
            log.error("", e);
            return R.error("异常：" + e.getMsg());
        }
    }

    /**
     * 1.3查询聚合支付对账数据，并返回对账文件给分行
     */
    @PostMapping("jhdzQuery")
    @ApiOperation("1.3查询聚合支付对账数据")
    @ResponseBody
    public R jhdzQuery(@Valid @RequestBody JhdzQueryRequest request) {

        try {
//            Date date1 = DateUtils.addDateDays(new Date(), request.getDay());
//            String date = DateUtils.format(date1, "yyyyMMdd");
            h5payService.jhdzQuery(request.getDay());
            return R.ok();
        } catch (RRException e) {
            log.error("", e);
            return R.error("异常：" + e.getMsg());
        }
    }

}
